package com.jpsl.core.util;

import java.io.Serializable;

public abstract class Pair<L, R> implements Serializable {

    public static <L, R> Pair<L, R> of(L left, R right) {
        Assert.notNull(left, "left");
        Assert.notNull(right, "right");
        return new ImmutablePair<>(left, right);
    }

    public abstract L getLeft();

    public abstract R getRight();

    private static class ImmutablePair<L, R> extends Pair<L, R> {

        private static final long serialVersionUID = -4954918890071093841L;

        private final L left;

        private final R right;

        private ImmutablePair(L left, R right) {
            this.left = left;
            this.right = right;
        }

        @Override
        public L getLeft() {
            return left;
        }

        @Override
        public R getRight() {
            return right;
        }

    }

}
